package cn.app.web.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.app.entity.DevUser;
import cn.app.service.DevUserService;

@Controller
@RequestMapping("/devUser")
public class DevUserController {
	
	@Autowired
	private DevUserService devUserService;
	
	//跳转登陆页面
	@RequestMapping("/disLogin")
	public String disLogin(){
		return "devLogin";
	}
	
	
	//登陆功能
	@RequestMapping("/login")
	public String login(@RequestParam(name="devcode",required=false) String devcode,
						@RequestParam(name="devpassword",required=false) String devpassword,
						HttpSession session,Model model){
		//讲数据传到service层验证
		DevUser devUser = devUserService.login(devcode,devpassword);
		if(devUser != null){
			//登陆成功
			session.setAttribute("devUser", devUser);
			return "redirect:/devApp/disMain";
		}else{
			//登陆失败
			model.addAttribute("loginInfo", "用户名或密码错误...");
			return null;
		}
		
	}
	
}
